//region 字面量，用得很少
let a: 10;
a = 10;
// a = 11; // 报错

let b: "male" | "female";
b = 'male';
b = 'female';
// b = 'gay'; // 报错

let c: boolean | string;
c = true;
c = false;
c = "abc";
c = 'cba';
// c = 1; // 报错
//endregion

//region any：任意类型，不建议使用
let d: any;
d = 10;
d = 'abc';

let e; // 什么都不写，相当于any
e = 10;
e = 'abc';

let f: string;
f = d; // any可以赋值给任意类型的变量
//endregion

//region unknown
let g: unknown;
g = 10;
g = true;
g = 'hello';

let g1: unknown;
g1 = 10;
g1 = 'hello';
g1 = true;

a = g; // 报错，unknown不能赋值给除了any、unknown以外类型的变量
e = g;
g1 = g;
//endregion

//region 类型断言
if (typeof g === 'number') {
    a = g;
}

// 类型断言
a = g as number;
a = <number>g; // 此种写法与上面的写法相同
//endregion

//region void
/**
 *
 * @param a {string}
 */
function f1(a: string): void {
    console.log(a);
}

function f2(a: string) {
    console.log(a);
}

// f1与f2等价

function f3(num: number) {
    if (num > 0) {
        return true;
    } else {
        return '123';
    }
}

//endregion

//region never
function f4(): never {
    throw new Error('error!');
}

function f5(): never {  //此函数不能声明返回值为never
    console.log("hello");
}

function f6(): never {
    console.log('hello');
    while (true) {

    }
}
//endregion